﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SRW;
using System.Text;
using SRW.BLL;

public partial class sysLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public Wtuser IsUser(string username, string password, string usertype)
    {
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.Append("select * from wtuser where ");
        sBuilder.Append(SqlFormat.FormatWhere("wtusername", publicConn.Quote(username)));
        sBuilder.Append(SqlFormat.FormatWhere("wtpassword", publicConn.Quote(password)));
        sBuilder.Append(SqlFormat.FormatWhere("wtusertype", publicConn.Quote(usertype), true, true));
        return bWtuser.select(sBuilder.ToString());
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string tmp = "";
        if (Session["mvc"] != null)
        {
            tmp = Session["mvc"].ToString();
        }
        if (string.IsNullOrEmpty(TextBox4.Text) || string.IsNullOrEmpty(TextBox1.Text))
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('未填写用户名或密码！')");
            return;
        }
        if (string.IsNullOrEmpty(TextBox2.Text))
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('请输入验证码！')");
            return;
        }
        if (TextBox2.Text.Trim().ToLower() == tmp.ToLower())
        {
            if (string.IsNullOrEmpty(TextBox4.Text) || string.IsNullOrEmpty(TextBox1.Text))
            {
                Anthem.Manager.AddScriptForClientSideEval("alert('未填写用户名或密码！')");
                return;
            }
            Wtuser mUser = null;
            mUser = IsUser(TextBox4.Text.Trim(), TextBox1.Text.Trim(), "管理员");
            if (mUser.pkID > 0)
            {
                Anthem.Manager.AddScriptForClientSideEval("alert('登录成功！')");
                CookieOper.CleanSession("mvc");
                Session["username"] = mUser.wtusername;
                Session["usertype"] = mUser.wtusertype;
                Response.Redirect("system/Manage/index.htm");
            }
            else
            {
                Anthem.Manager.AddScriptForClientSideEval("alert('用户名会密码错误，请确认！')");
            }
        }
        else
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('验证码错误，请重新输入！')");
            TextBox2.Text = "";
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("index.aspx");
    }
}
